package utils;

import ru.ipo.dces.server.http.IllegalClassException;
import ru.ipo.dces.server.http.PHP;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ReadWriteObject {

    public static <T> T readRequest(Class<T> cls, InputStream is) throws IOException, IllegalClassException,
            NoSuchFieldException, IllegalAccessException, InstantiationException {
        is.skip(2); // skip "x="
        return PHP.unserialize(cls, is);
    }

    public static <T> void writeResponse(T response, OutputStream out) throws IOException, IllegalAccessException {
        if (response != null) {
            out.write('N');
            out.write(';');
        }
        PHP.serialize(response, out);
    }
}
